/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import request from '@/utils/request';
import {
  ISceneCommunityDetails,
  ISceneCommunityItem,
  // ISceneCommunityList,
  // ISceneCommunityListParams,
  LatestScenesConfig,
} from '@/types/sceneCommunity';
import { IPromiseApi } from '@/types/type';
import base from './base';
import { paginationParams } from '@/utils/soa/utils';

//场景社区 列表
export async function getSceneCommunityList({
  current,
  pageSize,
  name,
  seriesCode,
  modelCode,
  latestScene,
  hotScene,
  officialScene,
}: any) {
  const _latestScene = latestScene || undefined;
  const _hotScene = hotScene || undefined;
  const _officialScene = officialScene || undefined;
  const { data } = await request.get(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenes`,
    {
      params: {
        ...paginationParams(current, pageSize),
        seriesCode,
        name,
        modelCode,
        latestScene: _latestScene,
        hotScene: _hotScene,
        officialScene: _officialScene,
      },
    },
  );

  return {
    list: data?.itemSize
      ? data?.dataList.map((item: ISceneCommunityItem, index: number) => ({
          ...item,
          index: index + 1 + (current - 1) * pageSize,
        }))
      : [],
    total: data?.pageCount,
  };
}

//场景社区 查看详情
export async function getSceneCommunityDetails(sceneRecordUuid: string) {
  return await request.get<IPromiseApi<ISceneCommunityDetails>>(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/scenes/detail`,
    {
      params: {
        sceneRecordUuid,
      },
    },
  );
}

//场景社区 最新场景配置查看
export async function getLatestScenesConfig() {
  return await request.get<IPromiseApi<LatestScenesConfig>>(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/latestscenesconfig`,
  );
}

//场景社区 最新场景配置保存
export async function saveLatestScenesConfig(data: LatestScenesConfig) {
  return await request.post(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/latestscenesconfig`,
    {
      data,
    },
  );
}

//场景社区 热门场景查看
export async function getHotScenesConfig() {
  return await request.get<IPromiseApi<{ topDownload: number }>>(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/hotscenesconfig`,
  );
}

//场景社区 热门场景配置保存
export async function saveHotScenesConfig(data: any) {
  return await request.post(
    `/${base.API}/ms-soa-scene-community/${base.VERSION}/admin/hotscenesconfig`,
    {
      data,
    },
  );
}

//场景社区 获取车系车型
export async function getCarSeriesModel() {
  return await request.get(`/${base.API}/ms-soa-vehicle/${base.VERSION}/admin/model/selected`);
}
